/**
 * Copyright [2012-2013] [Guðmundur Björn Birkisson]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License. Copyright [2012-2013] [Guðmundur Björn Birkisson]
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * ---------------------------------------------------------------------------
 * 
 * Class name:  KarelSplashScreen
 * 
 * Description of class:
 * 
 * Splashscreen for Karel
 * 
 */
package karel;

import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class KarelSplashScreen extends javax.swing.JFrame {

    private static KarelSplashScreen instance;
    
    public static KarelSplashScreen getInstance() {
        if(instance == null) {
            instance = new KarelSplashScreen();
        }
        return instance;
    }
    
    /**
     * Creates new form KarelSplashScreen
     */
    public KarelSplashScreen() {
        initComponents();
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        BufferedImage myPicture = null;
        try {
            myPicture = ImageIO.read(getClass().getResource("/images/icon.png"));
        } catch (IOException ex) {
            Logger.getLogger(KarelSplashScreen.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        JLabel picLabel = new JLabel(new ImageIcon( myPicture ));
        getContentPane().add(picLabel, java.awt.BorderLayout.CENTER);
        setPreferredSize(new Dimension(260,320));
        pack();
        setLocationRelativeTo(null);
    }

    public static void setProgressBarVal(int val) {
        getInstance().setP(val);
    }
    
    public static void close() {
        getInstance().setVisible(false);
    }
    
    public void setP(int val) {
        progressBar.setValue(val);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        progressBar = new javax.swing.JProgressBar();
        label = new javax.swing.JLabel();

        setUndecorated(true);
        setResizable(false);
        getContentPane().add(progressBar, java.awt.BorderLayout.PAGE_END);

        label.setFont(karel.util.FontLoader.getDefaultFont(karel.util.FontLoader.ButtonFontType,30));
        label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label.setText("Róbótinn Karel");
        getContentPane().add(label, java.awt.BorderLayout.PAGE_START);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel label;
    private javax.swing.JProgressBar progressBar;
    // End of variables declaration//GEN-END:variables
}
